<?php ob_start();?>
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/standart/dbconnect.php');

function goToMainPage(){
	echo '<script LANGUAGE="JavaScript">';
// 	echo 'parent.location="../";';
	echo 'window.location.href ="http://admin.gevezecafe.com/index.php?rnd="+Math.random();';
	echo '</script>';
}


if($_SERVER["REQUEST_METHOD"] == "POST")
{
	$myusername=utf8_decode($_POST['username']); 
	$mypassword=utf8_decode($_POST['password']);
	$db = connect();
	$sql="SELECT ID,USERNAME,PASSWORD FROM ADMIN WHERE USERNAME='$myusername' and PASSWORD=md5('$mypassword')";
	$res=$db->query($sql);
	if (($res->num_rows)!=0){
		$row=$res->fetch_assoc();
		if(isset($_POST['remember'])){
		setcookie("GEVEZE_ADMIN",$row["ID"], time()+(60*60),"/");
		setcookie("GEVEZE_ADMIN_USR",$row["USERNAME"], time()+(60*60*24*30),"/");
		setcookie("GEVEZE_ADMIN_PASS",$row["PASSWORD"], time()+(60*60*24*30),"/");
		}
		else
		{
		setcookie("GEVEZE_ADMIN",$row["ID"], time()+(60*60),"/");
		}
	  $res->close();
	  goToMainPage();
	}
	else{
		//header("Content-Type: text/html; charset=ISO-8859-9");
		echo '<script type="text/javascript">'
				,   'document.getElementsByName("username")[0].value = "";'
    			,	'document.getElementsByName("password")[0].value = "";'
    			,	'document.getElementsByName("username")[0].focus();'
				, '</script>'
				;
		echo "Yanlış Kullanıcı ya da Şifre!";

	}

	disconnect($db);
}

?>
<?php ob_end_flush(); ?>